package at.fhooe.im440.pandora.entities;

import java.awt.Graphics2D;
import java.awt.geom.Point2D;

import at.fhooe.im440.pandora.collision.CircleCollider;
import at.fhooe.im440.pandora.core.Core;
import at.fhooe.im440.pandora.graphics.RenderLayer;

public abstract class Entity extends CircleCollider{

	private static final int PREFIX_LENGTH = 2;

	private String name;
	protected Core core;
	private int renderLayer;

	public static String getTwoDigitLayer(int layer) {
		String s = Integer.toString(layer);
		if (s.length() == 1) {
			s = "0" + s;
		}
		return s;
	}

	public static int getLayerPrefixLength() {
		return PREFIX_LENGTH;
	}

	public Entity(String name, Core core, float x, float y, float radius) {
		super(x, y, radius);
		this.renderLayer = RenderLayer.BACKGROUND;
		this.name = name;
		this.core = core;
	}

	public String getNameWithLayer() {
		return getTwoDigitLayer(renderLayer) + name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getRenderLayer() {
		return renderLayer;
	}
	
	public void setRenderLayer(int renderLayer) {
		this.renderLayer = renderLayer;
		core.entityManager.requestRenderLayerUpdate();
	}
	
	public void updateCollider(float posX, float posY)
	{
		super.updateCollider(posX, posY);
	}
	
	public void updateCollider(float posX, float posY, float radius)
	{
		super.updateCollider(posX, posY, radius);
	}

	public abstract void update();
	
	public abstract void render(Graphics2D g);

	public abstract Point2D getPosition();
	
	public abstract void setPosition(float x, float y);

	public void drawCollider(Graphics2D g) {
		super.drawCollider(g);
	}

	public CircleCollider getCollisionObject() {
		return super.getCollisionObject();
	}
	
}
